#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys

from scpy.logger import get_logger
from xtls.mqwrapper import producer

reload(sys)
sys.setdefaultencoding("utf-8")
logger = get_logger(__file__)


@producer('10.117.29.191', 'stock_anno_download', logger=logger)
def insert_task():
    from pymongo import MongoClient
    conn = MongoClient('10.132.23.104', 27017)
    try:
        for index, item in enumerate(conn['stockProj']['shenhuStockAnno'].find()):
            logger.info('index : %s' % index)
            # if ('content' in item) or ('fileKey' in item):
            #     continue
            if item['downloadUrl'].lower().endswith('pdf'):
                yield {
                    '_id': item['_id'],
                    'downloadUrl': item['downloadUrl'],
                }
    except Exception, e:
        logger.exception(e)
    finally:
        conn.close()


if __name__ == '__main__':
    insert_task()
